package com.yesep.learn.design.behavioral.mediator;

import java.util.*;

/**
 * 具体中介者
 */
public class ConcreteMediator implements IMediator {
    private final List<IColleague> colleagues = new ArrayList<>();

    @Override
    public void register(IColleague colleague) {
        colleague.setMediator(this);
        colleagues.add(colleague);
    }

    @Override
    public void broadcast(String from, String to, String message) {
        for (IColleague cl : colleagues) {
            String name = cl.getName();
            if (name.equals(to)) {
                cl.receive(from, message);
            }
        }
    }
}
